package js;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class q小蓝旅行 {
    static int curOil;
    static List<List<Integer>> res = new ArrayList<>();
    static LinkedList<Integer> path = new LinkedList<>();

    public static void main(String[] args) {
        //输入的第一行包含两个整数nm ，用一个空格分隔。
        //接下来n行每行包含3个整数Dis; Cost; Lim;，相邻整数之间使用一个空格分隔。

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] dis = new int[n];
        int[] cost = new int[n];
        int[] lim = new int[n];
        curOil = m;
        for (int i = 0; i < n; i++) {
            dis[i] = scan.nextInt();
            cost[i] = scan.nextInt();
            lim[i] = scan.nextInt();
        }
        scan.close();
        backtracking(dis, lim, 0);
        if (res.size() == 0) System.out.println(-1);
        else {
            int min = Integer.MAX_VALUE;
            int tmp = 0;
            for (int i = 0; i < res.size(); i++) {
                for (int j = 0; j < res.get(i).size(); j++) {
                    tmp += res.get(i).get(j) * cost[j];
                }
                min = Math.min(min, tmp);
            }
            System.out.print(min);

        }
        //考虑使用回溯

    }


    static boolean backtracking(int[] dis, int[] lim, int startIndex) {
        if (startIndex >= dis.length - 1) {  // 此时从终点前一个结点出发能否到达终点
            if (curOil >= dis[startIndex]) {
                res.add(new ArrayList<>(path));
                return true;
            }
        }
        if (curOil < dis[startIndex]) { // 油不够
            return false;
        }

        if (curOil + lim[startIndex] < dis[startIndex]) return false;

        int j = 0;
        if(curOil>dis[startIndex]){
            j = 0;
        }else{
            j =  dis[startIndex]-curOil ;
        }

        for (; j <= lim[startIndex]; j++) {

            path.add(j);
            curOil = curOil - dis[startIndex] + j;
            backtracking(dis, lim, startIndex + 1);
            path.removeLast();
            curOil = curOil + dis[startIndex] - j;

        }

        return false;
    }
}
